import 'package:color_dart/RgbaColor.dart';
import 'package:flutter/material.dart';
import 'package:im_flutter_sdk_example/components/a_button/index.dart';
import 'package:im_flutter_sdk_example/utils/constants.dart';
import 'package:im_flutter_sdk_example/utils/global.dart';

class AllianceItem extends StatelessWidget {
  final item;
  const AllianceItem({Key key, this.item}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
          border: Border(
              bottom: BorderSide(
                  width: 1, color: Color.fromRGBO(242, 242, 242, 1)))),
      margin: EdgeInsets.only(bottom: 10),
      padding: EdgeInsets.symmetric(vertical: 10),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text('$item'),
          SizedBox(
            width: 60,
            height: 60,
            child: Container(
              child: Image.asset(
                'lib/assets/images/order/order1.png',
                width: 30,
                height: 30,
                fit: BoxFit.cover,
              ),
            ),
          ),
          Expanded(
            child: Padding(
              padding: const EdgeInsets.only(left: 10),
              child: Column(
                children: [
                  Row(
                    children: [
                      Text('国家知识产权运营公共服务平台', style: mainTitleStyle),
                    ],
                  ),
                  Padding(
                    padding: const EdgeInsets.only(top: 10, bottom: 15),
                    child: Row(children: [
                      spaceR(
                        AButton.normal(
                            width: 52,
                            height: 17,
                            bgColor: rgba(232, 243, 255, 1),
                            type: 'primary',
                            onPressed: () {},
                            child: Text('学术交流',
                                style: TextStyle(
                                    fontSize: 12,
                                    color: rgba(97, 142, 210, 1)))),
                      ),
                      spaceR(
                        AButton.normal(
                            width: 52,
                            height: 17,
                            bgColor: rgba(232, 243, 255, 1),
                            type: 'primary',
                            onPressed: () {},
                            child: Text('科研成果',
                                style: TextStyle(
                                    fontSize: 12,
                                    color: rgba(97, 142, 210, 1)))),
                      ),
                      spaceR(
                        AButton.normal(
                            width: 52,
                            height: 17,
                            bgColor: rgba(232, 243, 255, 1),
                            type: 'primary',
                            onPressed: () {},
                            child: Text('产业研究',
                                style: TextStyle(
                                    fontSize: 12,
                                    color: rgba(97, 142, 210, 1)))),
                      ),
                    ]),
                  ),
                  Text(
                    '数字园区借助物联网、大数据园区赋能数字园区借助物科研成果科研成果',
                    style: subtitleStyle,
                    maxLines: 2,
                  ),
                ],
              ),
            ),
          )
        ],
      ),
    );
  }

  Widget spaceR(Widget child) {
    return Container(
      margin: EdgeInsets.only(right: 10),
      child: child,
    );
  }
}

class AllianceList extends StatefulWidget {
  @override
  _AllianceListState createState() => _AllianceListState();
}

class _AllianceListState extends State<AllianceList>
    with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    super.build(context);
    return SingleChildScrollView(
      child: Container(
          color: Colors.white,
          padding: EdgeInsets.symmetric(horizontal: 10),
          child: Column(
            children: listData.map((item) => AllianceItem(item: item)).toList(),
          )),
    );
  }

  List listData = [];

  @override
  void initState() {
    super.initState();

    this.getData();
  }

  @override
  bool get wantKeepAlive => true;

  void getData() async {
    var res = await G.req.home.activityList();

    res.data['data']['list'].forEach((e) {
      listData.add(e);
    });

    this.setState(() {});
  }
}
